package batframework.code.util;

import java.lang.reflect.Method;

@SuppressWarnings("unchecked")
public	abstract class ClassUtils
{
	private final static String classpath = ClassUtils.class.getResource("/").getPath();
	
	/**
	 * @param classes
	 * @param methodName
	 * @return
	 */
	public static Method getMethod(Class<?> classes,String methodName)
	{
		Assert.notNull(classes,"the class is required");
		try{
			return classes.getMethod(methodName);
		}catch (NoSuchMethodException e){
			throw new IllegalArgumentException(e.getLocalizedMessage());
		}catch (SecurityException e){
			throw new IllegalArgumentException(e.getLocalizedMessage());
		}
	}

	
	public static Class<?> forName(String className)
	{
		try{
			return Class.forName(className);
		} catch (ClassNotFoundException e){
			return null;
		}
	}
	
	public static String getClassPath(String classPath)
	{
		return new StringBuilder(classpath).append(classPath).toString();
	}
	
	/**
	 * Create an object
	 * @param classes
	 * @return
	 */
	public static <T> T createObject(Class<?> classes)
	{
		Assert.notNull(classes);
		try{
			return (T) classes.newInstance();
		} catch (InstantiationException e){
			throw new IllegalArgumentException(e.getLocalizedMessage());
		} catch (IllegalAccessException e){
			throw new IllegalArgumentException(e.getLocalizedMessage());
		}
	}
}
